package com.qimo.service.Impl;

import com.qimo.dao.ShopDao;
import com.qimo.model.Book;
import com.qimo.model.CreateItem;
import com.qimo.model.Shop;
import com.qimo.model.ShopOrder;
import com.qimo.service.ShopService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("ShopService")
public class ShopServiceImpl implements ShopService {

    @Resource
    private ShopDao ShopDao;
    public int shopApplication(int userId, String shopName) {
        if(this.ShopDao.ShopCheckUserID(userId)!=null)//判断用户是否有店
            return -1;
        else if(this.ShopDao.ShopCheckShopName(shopName)!=null)//判断店名是否重复
            return-1;
        else {

            if(this.ShopDao.shopApplication(userId, shopName)>0)
                return this.ShopDao.updateUserType(userId);//注册店后更改用户类型为商家
            else return -1;
        }
    }

    public Shop Shop(int shopId) {
        System.out.println("传来的shopId:"+shopId);
       Shop temp=this.ShopDao.ShopSelect(shopId);
       if(null!=temp)
       temp.setShopItemList(this.ShopDao.ShopItemList(shopId));
       return temp;
    }



    public List<ShopOrder> shopOrderSelect(int userId,int Page,int limit) {
        return this.ShopDao.shopOrderSelect(userId,(Page-1)*limit,limit);
    }


    public Shop checkHaveShop(int userId) {
        return this.ShopDao.ShopCheckUserID(userId);
    }

    public int shopOrderSelectCount(int userId) {
        return this.ShopDao.shopOrderSelectCount(userId);
    }

    @Override
    public int fahuo(int userId) {
        return this.ShopDao.fahuo(userId);
    }

    @Override
    public int selectBookCount() {
        return this.ShopDao.selectBookCount();
    }

    @Override
    public List<Book> selectBook(int page, int limit) {
        return this.ShopDao.selectBook((page-1)*limit,limit);
    }

    @Override
    public int create_book_item(int userId, int itemId, List<Book> book,int shopId) {
        return this.ShopDao.create_book_item(book,itemId,shopId);
    }

    @Override
    public int createItem(CreateItem createItem) {
        this.ShopDao.createItem(createItem);
        return createItem.getId();
    }
}
